package net.optix.ip.commands
{
	import com.adobe.cairngorm.business.Responder;
	import com.adobe.cairngorm.commands.Command;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import mx.collections.ArrayCollection;
	
	import net.optix.ip.business.*;
	import net.optix.ip.model.ModelLocator;
	import net.optix.ip.vo.FirmVO;
	

	public class GetOrderFirmsCommand implements Command, Responder
	{
		// attributes ============================
		private var model : ModelLocator = ModelLocator.getInstance();


		// functions ============================
		public function execute( event:CairngormEvent ) : void
		{
			var delegate:ManagerDelegate	=	new ManagerDelegate();
			delegate.getOrderFirms(this);
		}
		
		//----------------------------------------------------------------------------
		public function onResult( event : * = null ) : void
		{
			var result:XML;
			var firms:ArrayCollection;
			var i:int	=	0;
			try
			{
				result		=	event.result.inventionfirms[0];
				firms		=	new ArrayCollection();
				for(i=0; i<result.Data.length(); i++)
				{
					firms.addItem(FirmVO.purseFirm(result.Data[i]));
				}
				model.inventionFirms	=	firms;
				
				result		=	event.result.trademarkFirms[0];
				firms	=	new ArrayCollection();
				for(i=0; i<result.Data.length(); i++)
				{
					firms.addItem(FirmVO.purseFirm(result.Data[i]));
				}
				model.trademarkFirms	=	firms;
				
				result		=	event.result.copyrightFirms[0];
				firms		=	new ArrayCollection();
				for(i=0; i<result.Data.length(); i++)
				{
					firms.addItem(FirmVO.purseFirm(result.Data[i]));
				}
				model.copyrightFirms	=	firms;
			}
			catch(error:Error)
			{
				
			}
		}
		
		//----------------------------------------------------------------------------
		public function onFault( event : * = null ) : void
		{
			
		}

	}
}